package com.xing.dao;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import com.xing.model.HsdAccount;
import com.xing.model.HsdModelSurveyListObj;
import com.xing.model.HsdQuestionAndAnswerModelListObj;
import com.xing.model.SuperObject;
import com.xing.my_model.HsdAccountObject;
import com.xing.util.AccessUrl;
import com.xing.util.Common;
import com.xing.util.MD5;

import android.content.Context;

public class CommonDao implements BaseDao{
	/**
	 * @param hostip  所请求数据对应的服务器地址.
	 * @param context  
	 * @return
	 */
	public static HsdQuestionAndAnswerModelListObj getQuestionAndAnswerModelList(String surveyuuids,String username,String token,Context context) throws Exception{
		String accessUrl = AccessUrl.getQuestionAndAnswerModelListUrl+"surveyuuid="+URLEncoder.encode(surveyuuids, "utf-8")+"&username="+URLEncoder.encode(username, "utf-8")+"&token="+token;;
		String result = Common.getUrl(accessUrl, context);
		HsdQuestionAndAnswerModelListObj obj = gson.fromJson(result,HsdQuestionAndAnswerModelListObj.class);
		return obj;
	}
	
	/**
	 * 得到问卷基本模型 信息
	 * @param url
	 * @param context
	 * @return
	 * @throws Exception
	 */
	public static HsdModelSurveyListObj getHsdModelSurveyListObj(String surveyuuids,String username,String token,Context context) throws Exception{
		String accessUrl = AccessUrl.getQuestionBasicModelListUrl+"surveyuuids="+URLEncoder.encode(surveyuuids, "utf-8")+"&username="+URLEncoder.encode(username, "utf-8")+"&token="+token;
		String result = Common.getUrl(accessUrl, context);
		HsdModelSurveyListObj obj = gson.fromJson(result,HsdModelSurveyListObj.class);
		return obj;
	}
	
	/**
	 * 上传问卷 问题和答案
	 * @param context
	 * @param hsdResearch
	 * @param resultlist
	 * @return
	 * @throws Exception
	 */
	public static SuperObject  upLoadHsdResult(Context context,String hsdResearch,String resultlist) throws Exception {
		List<String> key = new ArrayList<String>();
		List<String> value = new ArrayList<String>();
		key.add("research");
		key.add("resultlist");
//		key.add("research1");
//		key.add("resultlist1");
		value.add(hsdResearch);
		value.add(resultlist);
		String result = Common.downLoadByPost(context,AccessUrl.upLoadSurveyResultUrl, key, value);
		System.out.println("－－－－－－－－－－－－－－result----------------------"+result);
		SuperObject superObject = gson.fromJson(result, SuperObject.class);
		return superObject;
		
	}
	
	public static HsdAccountObject login(Context context,String user_name,String password,String deviceid) throws Exception{
		String accessUrl = AccessUrl.loginUrl+"username="+URLEncoder.encode(user_name, "utf-8")+"&password="+MD5.md5(password)+"&deviceid="+deviceid;;
		String result = Common.getUrl(accessUrl, context);
		HsdAccountObject hsdAccountObject = gson.fromJson(result,HsdAccountObject.class);
		return hsdAccountObject;
	}

}
